using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using Common;
using Infragistics.Win.UltraWinGrid;
using SWellPlate;

namespace MainView.MainControls
{
	public class CustomMergedCellEvaluator : IMergedCellEvaluator
	{
		private CollectionViewSource _view;

		public CustomMergedCellEvaluator(CollectionViewSource view)
		{
			_view = view;
		}

		public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column)
		{
			if (ConfigReader.GetInstance().GetMergerSampleResultFromIni() == 1 && column.Key == "WellCell.Well.Sample.Result.ConclusionList")
			{
				List<ChartData> list = _view.View.Cast<ChartData>().ToList();
				if (row1.Index < list.Count && row2.Index < list.Count)
				{
					if (list[row1.Index].WellCell.Well.Sample != null)
					{
						return list[row1.Index].WellCell.Well.Sample == list[row2.Index].WellCell.Well.Sample;
					}
					return false;
				}
			}
			return row1.Cells[0].Value.Equals(row2.Cells[0].Value);
		}
	}
}
